interface UserState {
	id: string,
	token: string,
	nickname: string,
	username: string,
	avator: string,
	addressList: AddressState[],
	goodList: any[],
	historyList: any[],
	collectList: any[],
	orderList: any[],
}

interface AddressState {
	id: string,
	tel: string,
	address: string,
	nickname: string
}

const initState: UserState = {
	id: '',
	token: '',
	nickname: '',
	username: '',
	avator: '',
	addressList: [],
	goodList: [],
	historyList: [],
	collectList: [],
	orderList: [],
}

export const userReducer = (state = initState, action: any): UserState => {
	switch (action.type) {
		case 'loginSuccess': {
			return {
				...state,
				...action.payload
			}
		}
		case 'quitLogin': {
			return {
				id: '',
				token: '',
				nickname: '',
				username: '',
				avator: '',
				addressList: [],
				goodList: [],
				historyList: [],
				collectList: [],
				orderList: [],
			}
		}
		default: return state
	}
}
